package com.example.lib_log.logger

import android.R.attr
import android.util.Log
import com.example.lib_log.LoggerLevel


/**
 * @author yaotianxue
 * @description 打印到logcat中
 * @date 2025/2/22
 */
class LogCatLogger:ILogger {
    private var isDebug = true //是否debug
    private var TAG = "" //默认TAG
    private var level = LoggerLevel.Debug //默认级别
    private var url = "" //保存地址
    private var loggerFormat = "%s====>%s"
    override fun v(tag: String, log: String) {
        if(isDebug && level.value >= LoggerLevel.Verbose.value){
            Log.v(TAG,String.format(loggerFormat,tag,log))
        }
    }
    override fun d(tag: String, log: String) {
       if(isDebug && level.value >= LoggerLevel.Debug.value){
           Log.d(TAG,String.format(loggerFormat,tag,log))
       }
    }



    override fun i(tag: String, log: String) {
        if(isDebug && level.value >= LoggerLevel.Info.value){
            Log.i(TAG,String.format(loggerFormat,tag,log))
        }
    }

    override fun w(tag: String, log: String) {
        if(isDebug && level.value >= LoggerLevel.Warn.value){
            Log.w(TAG,String.format(loggerFormat,tag,log))
        }
    }

    override fun e(tag: String, log: String) {
        if(isDebug && level.value >= LoggerLevel.Error.value){
            Log.e(TAG,String.format(loggerFormat,tag,log))
        }
    }

    override fun setDebug(isDebug: Boolean) {
        this.isDebug = isDebug
    }

    override fun setLogTAG(TAG: String) {
        this.TAG = TAG
    }

    override fun setLoggerLevel(level: LoggerLevel) {
        this.level = level
    }

    override fun setSaveUrl(url: String) {
        this.url = url
    }
}